package top.zxybird.demo.shardingjdbc.db;

import java.util.Collection;

import com.dangdang.ddframe.rdb.sharding.api.ShardingValue;
import com.dangdang.ddframe.rdb.sharding.api.strategy.database.SingleKeyDatabaseShardingAlgorithm;

/**
 * Created by zxybird on 2018/3/4.
 */
public class DbAlgorithm implements SingleKeyDatabaseShardingAlgorithm<Integer> {

  @Override
  public String doEqualSharding(Collection<String> collection, ShardingValue<Integer> shardingValue) {
    int id = shardingValue.getValue();

    int index = id % 2;

    for (String each : collection) {
      if (each.endsWith(index + "")) {
        return each;
      }
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Collection<String> doInSharding(Collection<String> collection, ShardingValue<Integer> shardingValue) {
    return null;
  }

  @Override
  public Collection<String> doBetweenSharding(Collection<String> collection, ShardingValue<Integer> shardingValue) {
    return null;
  }

}
